<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Hash;

class MemberController extends Controller
{
    //修改密码
    public function update_password(Request $request){
    	$uid = $request->user()->id;

    	$input = $request->input();

    	$data['password'] = Hash::make($input['password']);

        $users_result = Db::table('users')->where("id",'=',$uid)->first();

        if(!Hash::check($input['old_password'], $users_result->password))return response()->json(['message' => '密码错误不允许修改','code'=>'-1']);

    	Db::table('users')->where("id",'=',$uid)->update($data);

    	return response()->json([
            'code' => 1,
            'result' => [],
            'message' => '修改成功！'
        ]);
    }

    //查询ip
    public function select_ip(Request $request){
        $uid = $request->user()->id;

        $users_result = Db::table('users')->where("id",'=',$uid)->first();

        $ip = [];
        if(!empty($users_result->ip))$ip = explode(",", $users_result->ip);

        return response()->json([
            'code' => 1,
            'data' => $ip
        ]);
    }

    //查询设备
    public function select_machine(Request $request){
        $uid = $request->user()->id;

        $users_result = Db::table('users')->where("id",'=',$uid)->first();

        $machine = [];
        if(!empty($users_result->machine))$machine = explode(",", $users_result->machine);

        return response()->json([
            'code' => 1,
            'data' => $machine
        ]);
    }
}
